<script type="text/javascript">
function hitung_total(){
	var jumlah=0;
	$('input[id^="nominal_"]').each(function(){
		jumlah += parseFloat(this.value);
	});
	$('#total').val(jumlah);
	$('#total_div').html(jumlah);
	
}
function validasi_form(){
	var frm=document.forms['frm_bayar'];
	var total=$('#total').val();
	var total_tagihan=$('#total_tagihan').val();
	var total_bayar=$('#total_bayar').val();
	var sisa=total_tagihan-total_bayar;
	
	if((total > sisa)||(total > total_tagihan)){
		alert ("Pembayaran Harap Diisi Dengan Benar");
		return false;
	}else{
		//alert('ok');
		//return false;
		frm.submit();
	}
}
</script>

<div id="page-wrapper">
        <!-- /.row -->
    <div class="row">
        <div class="col-sm-12">
			<div class="panel panel-default">
                <div class="panel-heading"><span class="judul-page">Data Siswa</span><span class="pull-right">
					<a class="btn btn-warning btn-xs" href="<?php echo site_url('pembayaran_tahunan');?>">&nbsp;Kembali</a>
				</span>
				<div class="clearfix"></div>
				</div>
                <div class="panel-body">
					<table class="table table-striped table-bordered table-hover table-condensed">
							<tr>
								<td style="width:200px;"><span class="pull-left judul-hub">NIS</span></td>
								<td><?php echo $detail_siswa[0]->nis;?></td>
							</tr>
							<tr>
								<td><span class="pull-left judul-hub">Nama</span></td>
								<td><?php echo $detail_siswa[0]->nm_lengkap;?></td>
							</tr>
							<tr>
								<td><span class="pull-left judul-hub">Tahun Ajaran Masuk</span></td>
								<td><?php echo $detail_siswa[0]->th_ajaran;?></td>
							</tr>
							<tr>
								<td><span class="pull-left judul-hub">Status Tagihan</span></td>
								<td><b><?php echo $status;?></b></td>
							</tr>
						</table>
				</div>
			</div>
			<div class="panel panel-default">
                <div class="panel-heading"><span class="judul-page">Tagihan Yang harus Dibayar</span></div>
                <div class="panel-body">
					<table class="table table-striped table-bordered table-hover table-condensed">
						<tr>
							<th>No</th>
							<th>Komponen Tagihan</th>
							<th>Nominal</th>
						</tr>
						<?php
							if(isset($list_tagihan)){
								$no=1;
								$total_tagihan=0;
								foreach($list_tagihan as $val){
							
						?>
						<tr>
							<td><?php echo $no;?></td>
							<td><?php echo $val['nama_komp']?></td>
							<td><?php echo number_format($val['nominal'],0,",",".");?></td>
						</tr>
						<?php
							$no++;
							$total_tagihan+=$val['nominal'];
							}
						}
						?>
						<tr>
							<td colspan="2">Total</td>
							<td><?php echo number_format($total_tagihan,0,",",".");?></td>
						</tr>
					</table>
				</div>
			</div>
			<div class="panel panel-default">
                <div class="panel-heading"><span class="judul-page">Pembayaran Tagihan</span></div>
				<div class="panel-body">
				<form action="<?php echo site_url('pembayaran_tahunan/proses_pembayaran');?>" name="frm_bayar" id="frm_bayar" method="post">
					
					<table class="table table-striped table-bordered table-hover table-condensed">
						<tr>
							<th>No</th>
							<th>Nama Tagihan</th>
							<th>Dibayar</th>
							<th style="display:<?php echo $disp_bayar;?>">Bayar</th>
						</tr>
						<?php
							if(isset($list_tagihan)){
								$no=1;
								$total_bayar=0;
								foreach($list_tagihan as $val){
							
						?>
						<tr>
							<td><?php echo $no;?></td>
							<td><?php echo $val['nama_komp']?></td>
							<td><?php echo number_format($val['jml_bayar'],0,",",".");?></td>
							<td style="display:<?php echo $disp_bayar;?>">
							<input type="hidden" name="id_komp[]" id="komponen_<?php echo $no;?>" value="<?php echo $val['id_komponen'];?>"/>
							<input type="text" onChange="hitung_total();" value="0" name="nominal[]" id="nominal_<?php echo $no;?>" class="form-control input-sm" style="width:150px;"></td>
						</tr>
						<?php
							$total_bayar+=$val['jml_bayar'];
							$no++;
							}
						}
						?>
					<tr>
						<td colspan="2">Total</td>
						<td><input type="hidden" id="total_bayar" name="total_bayar" value="<?php echo $total_bayar;?>" />
						<input type="hidden" id="total_tagihan" name="total_tagihan" value="<?php echo $total_tagihan;?>" />
						<input type="hidden" id="total" name="total" value="0" />
						<input type="hidden" name="id_tapel" id="id_tapel" value="<?php echo $detail_siswa[0]->id_tapel_masuk;?>" />
						<input type="hidden" name="nis" id="nis" value="<?php echo $detail_siswa[0]->nis;?>" />
						<?php echo number_format($total_bayar,0,",",".");?></td>
						<td style="display:<?php echo $disp_bayar;?>"><div id="total_div"></div></td>
					</tr>
					</table>
					<div class="form-group" style="display:<?php echo $disp_bayar;?>">
                        <div class="col-sm-offset-2 col-sm-9">
						  <input type="button" onclick="validasi_form();" value="Simpan" name="kirim" class="btn btn-primary btn-sm">
                          <button type="reset" class="btn btn-danger btn-sm">Reset</button>
                        </div>
                      </div>
				</form>
				</div>
			</div>
        </div>
    </div>
    <!-- /.row -->
</div>
<!-- /#page-wrapper -->
